package com.kingre.et.dao.jpa;

import java.util.List;

import com.kingre.et.dao.ISchoolDAO;
import com.kingre.et.model.School;

public class SchoolDAOJPA extends GenericDAOJPA<School, Integer> implements ISchoolDAO {

    @SuppressWarnings("unchecked")
    public List<School> findByName(String name) {
        if (name == null || name.equals(""))
            return getJpaTemplate().find("FROM School p WHERE statusCode = true ORDER BY id");
        else
            return getJpaTemplate().find("FROM School p WHERE statusCode = true AND name like ? ORDER BY id",
                    "%" + name + "%");
    }

    @Override
    @SuppressWarnings("unchecked")
    public List<School> findAll() {
        return getJpaTemplate().find("FROM School p WHERE statusCode = true ORDER BY id");
    }

    @SuppressWarnings("unchecked")
    public List<School> findSubSchool(School school) {
        return getJpaTemplate().find(
                "FROM School p WHERE statusCode = true AND schoolType = 20 AND overSchool = ? ORDER BY id", school);
    }
}
